import { createHashRouter, Navigate } from "react-router";
import Login from '@/pages/login/index.jsx'
import Test from '@/pages/test/index.jsx'
import Home from '@/pages/home/index.jsx'
import Layout from '@/pages/layout/index.jsx'
import { HomeOutlined } from '@ant-design/icons'
import roleRoutes from './role.jsx'
import userRoutes from './user.jsx'

export const constantRoutes = [
    { path: "/login", hidden: true, element: (<Login />), },
    { path: "/test",hidden: true,  element: (<Test />) },
    { path: "/", hidden: true, element: <Navigate to="/home"  replace/> },
    {
      path: "/home",
      element: (<Layout></Layout>),
      meta: { title: "首页",  icon: <HomeOutlined />},
      children: [
        { index: true, element: <Home /> },
      ]
    },
    { path: "*", element: <Navigate to="/login" /> },
]

export const dynamicRoutes = [
  ...roleRoutes,
  ...userRoutes
]

// 全局路由
function globalRoute() {
  return createHashRouter([
    ...constantRoutes,
    ...dynamicRoutes,
  ])
}

const globalRouter = globalRoute()
export default globalRouter
